<?php

class AcessoController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    //ACTION: logar no sistema
    public function loginAction()
    {
        // Verifica se o usuário esta ativo no sistema...
        $modInscricao   = new Remanejamento_Model_Inscricao();
        $session        = $modInscricao->getSessaoInscricao('user');
        if (!empty($session)) {
            $this->_helper->redirector('etapa1', 'inscricao', 'remanejamento');
        }
        
        
        
        $formLogin      = new Application_Form_Login();
        $modLogin       = new Application_Model_Login();
        $post           = $this->getRequest()->getPost();
        $message        = '';
        
        if (!empty($post)) {
            if ($formLogin->isValid($post)) {
                $post   = $formLogin->getValues();
                $result = $modLogin->verificarLogin($post);
                
                if ($result['result'] == true) {
                    $this->_helper->redirector('etapa1', 'inscricao', 'remanejamento');
                    
                } else {
                    $message = $result['flashMsg'];
                }
            }
        } else {
            $modLogin->logout();
        }
        
        $this->view->message    = $message;
        $this->view->formLogin  = $formLogin;
    }
    
    //ACTION: sair do sistema
    public function logoutAction() 
    {
        $modAcesso = new Application_Model_Login();
        
        $modAcesso->logout();
        
        $this->_helper->redirector('login', 'acesso', 'default');
    }

}